<template>
  <div>
    <el-form :model="formData" label-width="80px" ref="form" :rules="rules">
      <el-form-item label="昵称" prop="nickname">
        <el-input v-model="formData.nickname" placeholder="请输入昵称"></el-input>
      </el-form-item>
      <el-form-item label="账号" prop="username">
        <el-input v-model="formData.username" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="formData.password" type='password' placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>  
        <el-button type="primary" @click="submit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {update} from "@/api/sys/admin.js"
  export default {
    props:[
      'row'
    ],
    watch:{
      row:{
        handler:function(val){
          if(val){
            this.formData = val;
          }
        },
        immediate:true
      }
    },
    data(){
      return {
        formData:{
          id:'',
          nickname:'',
          username:'',
          password:'',
        },
        rules:{
          nickname:[
            {required:true,message:'请输入昵称'}
          ],
          username:[
            {required:true,message:'请输入账号'}
          ],
          password:[
            {required:true,message:'请输入密码'}
          ]
        }
      }
    },
    methods:{
      submit(){
        this.$refs.form.validate(valid=>{
          if(valid){
            update(this.formData).then(res=>{
              this.$message.success("更新成功")
              this.$emit('success')
            })
          }          
        })
      }
    }
  }
</script>

<style scoped>

</style>